package com.sample.base.ui.activity

import android.content.DialogInterface
import android.view.WindowManager
import androidx.appcompat.app.AlertDialog
import com.loyal.helper.DialogHelper
import com.loyal.dialog.LoadingDialog
import com.loyal.kit.StateBarUtil
import com.sample.base.R
import com.sample.base.base.BaseActivity
import com.sample.base.databinding.ActivityFullscreenBinding

class FullScreenActivity : BaseActivity() {
    private val binding by lazy { ActivityFullscreenBinding.inflate(layoutInflater) }

    override fun setLayoutOrView() {
        setContentView(binding.root)
    }

    override fun isFullScreen(): Boolean {
        return true
    }

    override fun afterOnCreate() {
        StateBarUtil.hideNavigationBar(this)
        binding.loading.setOnClickListener {
            showProgress()
            //showAlert()
        }
        binding.dialog.setOnClickListener {
            showMessage()
        }
        binding.alert.setOnClickListener {
            showAlert()
        }
    }

    private fun showProgress() {
        val progress = LoadingDialog.show(this, "", "测试")
        progress.setCancelable(true)
        progress.setFullScreen(isFullScreen)
        progress.setCanceledOnTouchOutside(true)
        progress.show()
    }

    private fun showAlert() {
        val builder = AlertDialog.Builder(this)
        builder.setIcon(R.mipmap.ic_update)
        builder.setTitle("AlertIcon")
        builder.setPositiveButton("确 定") { dialog, _ -> dialog?.dismiss() }
        builder.setNegativeButton("取 消") { dialog, _ -> dialog?.dismiss() }
        //val dialog = builder.show()
        val dialog = builder.create()
        val window = dialog.window

        window?.setFlags(
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
        )

        dialog.setOnShowListener {
            DialogHelper.showFullScreen(window, isFullScreen)
        }
        dialog.show()
    }

    private fun showMessage() {
        val alertDialog = DialogHelper.createMessageDialog(this, "测试")
        alertDialog?.setIcon(R.mipmap.ic_update)
        alertDialog?.setTitle("显示Icon")
        alertDialog?.setFullScreen(isFullScreen)
        alertDialog?.setButton(
            DialogInterface.BUTTON_POSITIVE, "确 定"
        ) { dialog, _ -> dialog?.dismiss() }
        alertDialog?.setButton(
            DialogInterface.BUTTON_NEGATIVE, "取 消"
        ) { dialog, _ -> dialog?.dismiss() }
        alertDialog?.show()
    }

}